package com.ysl.study.designpattern.structure.proxy;

/**
 * 代理模式测试
 *
 * @author yangshanlin
 * @date 2023/3/4 16:55
 * @describe
 */
public class ProxyTest {

    public static void main(String[] args) {
        proxy();
//        jdkProxy();
//        cglibProxy();
    }

    /**
     * 静态代理
     */
    public static void proxy(){
        Movie movie = new Movie();
        IMovie proxy = new MovieProxy(movie);

        movie.play("自己播放电影");
        System.out.println("=========");
        proxy.play("电影院播放电影");
    }

    /**
     * JDK动态代理
     */
    public static void jdkProxy(){
        IMovie movie = new Movie();
        IMovie proxy = (IMovie) new JdkMovieProxy(movie).getProxyInstance();

        movie.play("自己播放电影");
        System.out.println("=========");
        proxy.play("电影院播放电影");
    }

    /**
     * CGLIB动态代理
     */
    public static void cglibProxy(){
        IMovie movie = new Movie();
        IMovie proxy = (IMovie) new CglibProxy(movie).getProxyInstance();

        movie.play("自己播放电影");
        System.out.println("=========");
        proxy.play("电影院播放电影");
    }
}
